<?php
class database{
	
	var $host = 'localhost';
	var $user = 'root';
	var $pass = 'root';
	
	var $_sql = '';
	var $_connection = '';
	var $_cursor = null;
	
	function database()
	{
		$this->_connection=@mysql_connect($this->host,$this->user,$this->pass);
		if(!$this->_connection)
		{
			die("không thể kết nối cơ sở dữ liệu");
		}
		$db='quanlydiadiem';
		mysql_query("SET NAMES 'utf8'");
		mysql_query("SET CHARACTER SET utf8");
		if($db!=''&&!mysql_select_db($db,$this->_connection))
		{
			die("không thể mở csdl".mysql_error());
		}
		
	}
	
	function setQuerry($sql)
	{
		$this->_sql=$sql;
	}
	
	function loadAllRow()
	{
		if(!($cur=$this->querry()))
			return null;
		$array=array();
		while($row=mysql_fetch_assoc($cur))
		{
			$array[]=$row;
			
		}
		mysql_free_result($cur);
		return $array;
	}
	function querry()
	{
		$this->_cursor=mysql_query($this->_sql,$this->_connection);
		return $this->_cursor;
	}
	
	function disconnection()
	{
		mysql_close($this->_connection);
	}
}
?>
